import java.util.concurrent.FutureTask;

/**
 * @author 杨亚旭
 * @date 2019-01-29-9:47
 **/
public class Execute {
    public static void main(String[] args) throws InterruptedException {


        //--------------------------------------------
        //直接继承thread类
        ThreadSon son1=new ThreadSon("thread1");
        son1.start();
        ThreadSon son2=new ThreadSon("thread2");
        son2.start();
        //执行结果发现，线程1 线程2 都走了run方法的逻辑
        //--------------------------------------------


        //--------------------------------------------
        //实现runabale接口
        RunnableImpl runnable=new RunnableImpl();
        Thread thread1=new Thread(runnable);
        thread1.start();
        Thread thread2=new Thread(runnable);
        thread2.start();
        //线程1 线程2都用了runnable这个对象实例，然后这两个线程是对这个实例里面的任务分了一下，1,2各走了一部分
        //--------------------------------------------

        //--------------------------------------------
        // 实现Callable接口，可以有返回值
        CallableImpl callableImpl=new CallableImpl();
        Thread callableThread1 = new Thread(new FutureTask(callableImpl),"callableThread1");
        callableThread1.start();
        Thread callableThread2 = new Thread(new FutureTask(callableImpl),"callableThread2");
        callableThread2.start();

        //--------------------------------------------



        //----------thread2如何等待线程1执行完再执行-----------
        SerialThread serialThread =new SerialThread("1");
        SerialThread serialThread1 =new SerialThread("2");
        serialThread.start();
        //join（）对线程修饰后，其他线程就会等待状态，一直等该线程执行结束后才会进行其他线程（主线程和其他线程）的操作
        //如果不对serialThread1线程加join（）则县城内的业务代码 和主线程的输出语句顺序不可控
        serialThread.join();
        serialThread1.start();

        //serialThread1.join();
        System.out.println("=============");


        //--------------------------------------------


    }


}
